<?php

require_once 'PHPUnit/Framework.php';

CCore::Using('mime.parameter');

/**
 * Test class for CCoreMimeParametersCollection.
 */
class CCoreMimeParametersCollectionTest extends PHPUnit_Framework_TestCase
{
	public function testMimeParametersCollection0()
	{
		$oMimeParametersCollection = new CCoreMimeParametersCollection(
			'filename="file.txt"; charset="utf-8"; custom="value"');
		
		$this->assertEquals(3, $oMimeParametersCollection->Count());
		$this->assertEquals('file.txt', $oMimeParametersCollection->GetParamValueByName('filename'));
		$this->assertEquals('utf-8', $oMimeParametersCollection->GetParamValueByName('charset'));
		$this->assertEquals('value', $oMimeParametersCollection->GetParamValueByName('custom'));
		$this->assertEquals('', $oMimeParametersCollection->GetParamValueByName('notExist'));
	}

	public function testMimeParametersCollection1()
	{
		$oMimeParametersCollection = new CCoreMimeParametersCollection(
			'filename*0*=111; filename*1*=222.doc; charset="utf-8"');

		$this->assertEquals(2, $oMimeParametersCollection->Count());
		$this->assertEquals('111222.doc', $oMimeParametersCollection->GetParamValueByName('filename'));
		$this->assertEquals('utf-8', $oMimeParametersCollection->GetParamValueByName('charset'));
		$this->assertEquals('', $oMimeParametersCollection->GetParamValueByName('notExist'));
	}

	public function testAdd()
	{
		$oMimeParametersCollection = new CCoreMimeParametersCollection(
			'filename="file.txt"; charset="utf-8"');
		$this->assertEquals(2, $oMimeParametersCollection->Count());

		$oMimeParameter = new CCoreMimeParameter('Key', 'Value');
		$oMimeParametersCollection->Add($oMimeParameter);
		$this->assertEquals(3, $oMimeParametersCollection->Count());

		$oMimeParametersCollection->Clear();
		$this->assertEquals(0, $oMimeParametersCollection->Count());
	}
}
